package com.nthink.indicators.service.hospitalindicators.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nthink.indicators.mapper.hospitalindicators.ResourceAllocationMapper;
import com.nthink.indicators.pojo.hospitalindicators.ResourceAllocation;
import com.nthink.indicators.pojo.pie.PieDataModel;
import com.nthink.indicators.service.hospitalindicators.ResourceAllocationService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ResourceAllocationServiceImpl extends ServiceImpl<ResourceAllocationMapper, ResourceAllocation> implements ResourceAllocationService {


    public ResourceAllocation getData() {
        ResourceAllocation resourceAllocation = new ResourceAllocation();
        resourceAllocation.setOpenBeds(baseMapper.getOpenBeds());
        resourceAllocation.setIcuBeds(baseMapper.getIcuBeds());
        resourceAllocation.setEmergencyBeds(baseMapper.getEmergencyBeds());
        resourceAllocation.setMedicalStaff(baseMapper.getMedicalStaff());
        resourceAllocation.setIcuBedsPercent((double) resourceAllocation.getIcuBeds() / (double) resourceAllocation.getOpenBeds());
        resourceAllocation.setMedicalStaffProportion((double) resourceAllocation.getIcuBeds() / (double) resourceAllocation.getMedicalStaff());
        return resourceAllocation;
    }

    public List<PieDataModel> getResourceAllocation() {
        ResourceAllocation resourceAllocations = getData();

        List<PieDataModel> dataModelList = new ArrayList<>();
        dataModelList.add(new PieDataModel("emergencyBeds", resourceAllocations.getEmergencyBeds(), "急诊留观床位"));
        dataModelList.add(new PieDataModel("icuBeds", resourceAllocations.getIcuBeds(), "重症医学科床位"));
        dataModelList.add(new PieDataModel(null, resourceAllocations.getOpenBeds() - resourceAllocations.getIcuBeds() - resourceAllocations.getEmergencyBeds(), "其他科室总床位"));

        return dataModelList;

    }

    @Override
    public Integer getBedCount() {
        return baseMapper.getOpenBeds();
    }
}
